const getVueTemplate = (componenetName) => `
<div class="detail-title-panel"><span class="baseInfo-icon"></span><span>基本信息</span></div>
<div class="btn-panel">
  <el-button type="primary" @click="${componenetName}TableData.push({})" v-if="!isView"
    ><span class="iconfont icon-tianjia"></span>新增</el-button
  >
</div>
<div class="detail-table-panel">
  <el-table border :data="${componenetName}TableData">
    <el-table-column type="index" width="50" label="序号" header-align="center" align="center"></el-table-column>
    <el-table-column
    v-for="(item, index) in ${componenetName}TableHeaders"
    :min-width="item.width ? item.width : 'auto'"
    :show-overflow-tooltip="true"
    :key="index"
    :label="item.name"
    header-align="center"
    :align="item.align"
    :prop="item.code"
    >
      <template slot-scope="scope">
        <span>{{ scope.row[item.code] }}</span>
      </template>
    </el-table-column>
    <el-table-column label="操作" width="90" header-align="center" align="center" v-if="!isView">
      <template slot-scope="scope">
        <collapseBtnWrapper
          :btnConfig="${componenetName}BtnConfig"
          ref="btnWrapper"
          :disabledItems="isView ? ['delete', 'edit'] : []"
          :owner="scope.row"
        />
      </template>
    </el-table-column>
  </el-table>
</div>`;
const getDataTemplate = (componenetName) => `
${componenetName}TableData: [],
${componenetName}TableHeaders: [
  {
    name: '项目名称',
    code: 'workStepName',
    width: 100,
  },
  {
    name: '合格品数量',
    code: 'goodQty',
    width: 100,
  },
],
${componenetName}BtnConfig: [
  {
    label: '删除',
    name: 'delete',
    type: 'danger',
    cb: row => {
      const idx = this.${componenetName}TableData.findIndex(item => item === row);
      if (idx > -1) {
        this.${componenetName}TableData.splice(idx, 1);
      }
    },
    eleType: 'Delete',
  },
],`;
const getModifyTemplate = (componenetName) => [
  //template
  {
    repeatReg: new RegExp(`:data=["']${componenetName}TableData['"]`),
    targetReg: /(<\/\S*>[\s]*<\/template>[\s]*?<script>)/,
    tagetReplace: `${getVueTemplate(componenetName)}\n$1`,
  },
  // 定义data
  {
    repeatReg: new RegExp(`${componenetName}TableData:\\s*\\[\\]`),
    targetReg: /data\(\)\s*{([\s]*?)return[\s]*{/,
    tagetReplace: `data\(\) {$1return {
     ${getDataTemplate(componenetName)} `,
  },
];
module.exports = {
  getModifyTemplate,
};
